package cn.stronglink.asset.module.dam.service;

import java.util.List;

import javax.jms.JMSException;
import javax.jms.TextMessage;

import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSON;

import cn.stronglink.asset.message.mq.dam.CommandReceiver;
import cn.stronglink.asset.module.dam.entity.dev.AssetInfo;
import cn.stronglink.asset.module.dam.entity.dev.RackInfo;
import cn.stronglink.asset.module.dam.entity.message.MsgScreenCommand;
import cn.stronglink.asset.module.dam.entity.message.MsgSensorTypeSetting;
import cn.stronglink.asset.module.dam.entity.message.basicMsg.DamMqMessage;
import cn.stronglink.asset.module.dam.entity.message.secondMsg.AwsPostdataCommand;
import cn.stronglink.asset.module.dam.entity.message.secondMsg.AwsPostdataSensorTypeSetting;
import cn.stronglink.asset.module.dam.interfaces.CommandStrategyI;
import cn.stronglink.asset.module.dam.mapper.DamSensorMapper;
import cn.stronglink.asset.module.dam.utils.factorys.req.Factory3AssetInfo;

@Service("getAssetInfoAtRackService")
public class ScreenReqGetAssetInfoAtRackService implements CommandStrategyI {
	@Autowired
	private DamSensorMapper damSensorMapper;

	@Override
	public void handleDamDatas(DamMqMessage msg) {
		MsgScreenCommand msgScreenCommand = (MsgScreenCommand) msg;
		AwsPostdataCommand datas = msgScreenCommand.getAwsPostdata();
		String rackConverCode = datas.getRackConverCode();

		// 获取当前页 + 翻页参数： 是上一页/下一页？
		int currPage = 1, maxCount = 24, startIndex = (currPage - 1) * maxCount;// 分页查询
		int viewParam = CommandReceiver.viewParam;
		int currPageParam = CommandReceiver.currPage;
		
		// 使用翻页参数--查询数据库
		if (viewParam != -1 && currPageParam > 1) {
			currPage = viewParam == 0// 0300上一页 0301下一页
					? currPageParam - 1
					: currPageParam + 1;

		}
		System.out.println("startIndex  " + startIndex);
		List<AssetInfo> list = damSensorMapper.getAssestInfoInRack(rackConverCode, startIndex, maxCount);

		// 打印查询的信息
		System.out.println("资产信息==========》");
		for (AssetInfo mes : list) {
			if (mes != null) {
				System.out.println(mes.getAssetName());
				System.out.println(mes.getAssetNo());
				System.out.println(mes.getAssetStatus());
				System.out.println(mes.getEndU());
				System.out.println(mes.getStartU());
			}
		}
		System.out.println("资产信息==========》end");
		Factory3AssetInfo.open3AssertInfo(msgScreenCommand, list);
	}

	@Override
	public boolean isHandle(int screenId) {
		// 3: 资产信息
		if (screenId == 3)
			return true;
		return false;
	}

}
